﻿@using LanDBom.Models
@{
    ViewBag.Title = "BomsView";
    Layout = "~/Views/Shared/_Genertals.cshtml";
}

<from>
    <fieldset class="boun">
        <legend></legend>
        <div class="row bian">
            <label class="col-sm-3 breadcrumb-item active">步骤四：粗报价报表</label>
            <ul id="lisul" class="row col-sm-5">
                <li class="lisu"></li>&rArr;
                <li class="lisu"></li>&rArr;
                <li class="lisu"></li>&rArr;
                <li class="lisu">4</li>&rArr;
                <li class="lisu"></li>
            </ul>
        </div>
    </fieldset>
</from>
<div>
    <form action="" class="boun">
        <fieldset class="len">客户详情</fieldset>
        <table class="table">
            @foreach (var item in ViewBag.ListAPP as List<Applications>)
            {
                <tr>
                    <td>@Html.Label("客户名称:")@item.App_Kehu</td>
                    <td id="App_bian" style="display:flex;">@Html.Label("申请编号:")<p id="hunf">@item.AP_bian</p>  </td>
                </tr>
                <tr>
                    <td>@Html.Label("发布日期:")@item.App_qishi</td>
                    <td>@Html.Label("截止日期:")@item.App_JTime</td>
                </tr>
                <tr>
                    <td>@Html.Label("项目名称:")@item.APP_name</td>
                    <td>@Html.Label("询价目的:")@item.App_mu</td>
                </tr>
                <tr>
                    <td>@Html.Label("运送地址:")@item.App_dizhi</td>
                </tr>
            }
        </table>
    </form>
    <div>
        <button class="btn" id="SCbao">生成报表</button>
        <button class="btn">设置成模板</button>
    </div>
    <div title="工艺详细" id="BJ_GYXX" style="display:none;position:fixed;" class="CenterDiv1">
        <div>
            <table class="table table-sm gun" style="background-color:darkgray;">
                <thead class="thead-light">
                    <tr>
                        <th scope="col">序号</th>
                        <th scope="col">印刷</th>
                        <th scope="col">印色</th>
                        <th scope="col">模切</th>
                        <th scope="col">木箱包角</th>
                        <th scope="col">表面处理</th>
                        <th scope="col">模具</th>
                        <th scope="col">提供模具</th>
                        <th scope="col">物理要求</th>
                        <th scope="col">加工费</th>
                    </tr>
                </thead>
                <tbody data-spy="scroll" style="background-color:darkgray;" id="BJ_oper_tbo">
                </tbody>
            </table>
            <div id="BJ_GYFH">
                返回
            </div>
        </div>
    </div>
    <div title="图纸详细" id="BJ_TU" style="display:none;position:fixed;" class="CenterDiv1">
        <div>
            <table class="table table-sm gun" style="background-color:darkgray;">
                <thead class="thead-light">
                    <tr>
                        <th scope="col">序号</th>
                        <th scope="col">申请人</th>
                        <th scope="col">申请时间</th>
                        <th scope="col">图纸类型</th>
                        <th scope="col">图纸路径</th>
                        <th scope="col">操作</th>
                    </tr>
                </thead>
                <tbody data-spy="scroll" style="background-color:darkgray;" id="BJ_oper_tbody">
                </tbody>
            </table>
            <div id="BJ_GYFH">
                返回
            </div>
        </div>
    </div>
    <div title="Bom详情">
        <div>
            <table class="table table-sm gun">
                <thead class="thead-light">
                    <tr>
                        <th scope="col">序号</th>
                        <th scope="col">层次</th>
                        <th scope="col">物料信息</th>
                        <th scope="col">料号</th>
                        <th scope="col">客户料号</th>
                        <th scope="col">年用量</th>
                        <th scope="col">Bom用量</th>
                        <th scope="col">供应商</th>
                        <th scope="col">价格</th>
                        <th scope="col">单位</th>
                        <th scope="col">BOM价格</th>
                        <th scope="col">操作</th>
                    </tr>
                </thead>
                <tbody data-spy="scroll" id="BJ_BOM_tbody">
                </tbody>
                @*<tfoot>
                        <tr>
                            <th colspan="8" style="text-align:center">合计</th>
                            <th></th>
                            <th colspan="2" style="text-align:center">@(Session["T_pricesed"]) 元</th>
                        </tr>
                    </tfoot>*@
            </table>
        </div>
    </div>
    <button class="" id="sdfghj">保存</button>
    @section scripts{
        <script src="~/Scripts/jquery-3.4.1.min.js"></script>
        <script>
            $(function () {
                var names = $("#hunf").text();
                $.ajax({
                    url: "/Cuobaojia/BomsView",
                    type: "POST",
                    data: { "names": names, "state": 1 },
                    success: function (date) {
                        createTR(date)
                    },
                    error: function () {
                        alert("Error")

                    }
                })
                $("#SCbao").click(function () {
                    var shen = $("#hunf").text();
                    $.ajax({
                        url: "/Detailed/Excelwen",
                        type: "POST",
                        data: { "names": names },
                        success: function (date) {
                            createTR(date)
                        },
                        error: function () {
                            alert("Error")

                        }
                    })
                })
                $("#sdfghj").click(function () {
                    var shunf = [];
                    $("#BJ_BOM_tbody tr").each(function (itemed, obj) {
                        shunf.push({
                            BOM2_id: $('#jidnj', obj).text(),
                            BOM2_chen: $("#one", obj).text(),
                            BOM2_mioa: $("input[name='dfgsd']", obj).val()
                        })
                    })
                    $.ajax({
                        url: "/Cuobaojia/Xiugai",
                        type: "POST",
                        data: JSON.stringify(shunf),
                        contentType: "application/json;charset=utf-8",
                        dataType: "json",
                        success: function (date) {
                            alert(date)
                        },
                        error: function () {
                            alert("Error")

                        }
                    })
                })
            })

            function createTR(date) {
                $('#BJ_BOM_tbody tr').remove();
                $.each(date, function (i, item) {
                    $th = $(`<input type="number" value="${item.BOM2_mioa}" style="width:70px;" min="0" name="dfgsd"/><span>元</span> `);
                    if (item.BOM2_chen != "Leve0") {
                        $th = "";
                    }
                    var $tr = $(`
                            <tr>
                                <td></td>
                                <td style="display:none;" id="jidnj">${item.BOM2_id}</td>
                                <td id="one" class="plij">${item.BOM2_chen}</td>
                                <td>${item.BOM2_wuLiu}</td>
                                <td>${item.BOM2_liao}</td>
                                <td>${item.BOM2_duan}</td>
                                <td>${item.BOM2_Nian}</td>
                                <td>${item.BOM2_Yong}</td>
                                <td>${item.Nd_Gong}</td>
                                <td >${item.Nd_jiage}</td>
                                <td>${item.Nd_danwei}</td>
                                <td style="display:none">${item.BOM2_Gong}</td>
                                <td style="font-size:20px;" id="Leve0_P"></td>
                                <td ><span id="BJ_CKGY">工艺</span>|<span id="BJ_TUZHI">图纸</span></td>
                            </tr>
                        `);
                    $('#BJ_BOM_tbody').append($tr);
                    $(".plij").each(function (i, obj) {
                        if ($(obj).text() == "Leve0") {
                            $(obj).parent().children().last().prev().append($th)
                        }
                    })
                })
                
                var len = $('#BJ_BOM_tbody tr').length;
                for (var i = 0; i < len; i++) {
                    $('#BJ_BOM_tbody tr:eq(' + i + ') td:first').text(i + 1);

                }
            }
            $(document).on("click", "#BJ_CKGY", function (e) {
                $("#BJ_GYXX").css({ "display": "block" })
                var BOM_Gong = $(e.target).prev().prev().text()
                $.ajax({
                    url: "/Cuobaojia/BomsView",
                    type: "POST",
                    data: { "BOM_Gong": BOM_Gong, "state": 2 },
                    success: function (data) {
                        createTR(data)
                    },
                    error: function () {
                        alert("Error")

                    }
                })
                function createTR(data) {
                    $('#BJ_oper_tbody tr').remove();
                    $.each(data, function (i, item) {
                        var $tr = $(`
                                                <tr>
                                                    <td>${item.OP_ID}</td>
                                                    <td>${item.OP_Yin}</td>
                                                    <td>${item.OP_YinSe}</td>
                                                    <td>${item.OP_Muqie}</td>
                                                    <td>${item.OP_Muxinag}</td>
                                                    <td>${item.OP_biao}</td>
                                                    <td>${item.OP_Mujiu}</td>
                                                    <td>${item.OP_Tigong}</td>
                                                    <td>${item.OP_Wuli}</td>
                                                    <td>${item.OP_price}</td>
                                                </tr>
                                            `);
                        $('#BJ_oper_tbody').append($tr);
                    })
                }
            })
            $(document).on("click", "#BJ_TUZHI", function (e) {
                $("#BJ_TU").css({ "display": "block" })
                var BOM_Gong = $(e.target).prev().prev().text()
                $.ajax({
                    url: "/Cuobaojia/BomsView",
                    type: "POST",
                    data: { "BOM_Gong": BOM_Gong, "state": 3 },
                    success: function (data) {
                        createTR(data)
                    },
                    error: function () {
                        alert("Error")

                    }
                })
                function createTR(data) {
                    $('#BJ_oper_tbody tr').remove();
                    $.each(data, function (i, item) {
                        var $tr = $(`
                                <tr>
                                    <td>${item.DE_id}</td>
                                    <td>${item.De_ren}</td>
                                    <td>${item.DE_tuiLei}</td>
                                    <td>${item.De_shijian}</td>
                                    <td>${item.De_dizhi}</td>
                                    <td></td>
                                </tr>
                            `);
                        $('#BJ_oper_tbo').append($tr);
                    })
                }
            })
            $(document).on("click", "#BJ_GYFH", function () {
                $("#BJ_GYXX").css({ "display": "none" })
                $("#BJ_TU").css({ "display": "none" })
            })
        </script>
    }
</div>